package com.tbsoft.ehr.service.staffile;

import java.io.IOException;
import java.util.List;

import com.tbsoft.ehr.dao.contract.ContractDao;
import com.tbsoft.ehr.dao.staffFile.StaffFileDao;
import com.tbsoft.ehr.model.AttachFile;
import com.tbsoft.ehr.model.StaffInfo;

public class StaffFileServiceImpl implements StaffFileService {

	private StaffFileDao staffFileDao;
	private ContractDao contractDao;

	public StaffFileDao getStaffFileDao() {
		return staffFileDao;
	}

	public void setStaffFileDao(StaffFileDao staffFileDao) {
		this.staffFileDao = staffFileDao;
	}

	public ContractDao getContractDao() {
		return contractDao;
	}

	public void setContractDao(ContractDao contractDao) {
		this.contractDao = contractDao;
	}

	public StaffInfo addStaffFile(StaffInfo staffInfo,List<AttachFile> attachFileList) throws IOException {
		StaffInfo si = this.getStaffFileDao().save(staffInfo);
		this.getStaffFileDao().saveOrUpdateAttachfile(attachFileList, si.getStaffId());
		return si;
	}

	public List<StaffInfo> getAllStaffFile() {
		return this.getStaffFileDao().getAllStaffInfo();
	}

	public List<StaffInfo> getStaffFileByCondton(StaffInfo staffInfo,String dateFrom,String dateTo,int startIndex,int count) {
		List<StaffInfo> lst = this.getStaffFileDao().getStaffInfoByCondton(staffInfo, dateFrom, dateTo,startIndex,count);
		return lst;
	}

	public void deleteStaff(StaffInfo staff) {
		String staffId = staff.getStaffId();
		//逻辑删除档案
		getStaffFileDao().logicDelete(StaffInfo.class, staffId);
		//逻辑删除其合同
		getContractDao().logicDelete(staffId);
	}

	public StaffInfo getStaffFileById(String id) {
		return this.getStaffFileDao().getStaffInfoById(id);
	}

	public StaffInfo updateStaffFile(StaffInfo staffInfo,List<AttachFile> attachFileList) throws IOException {
		StaffInfo si = this.getStaffFileDao().saveOrUpdate(staffInfo);
		this.getStaffFileDao().saveOrUpdateAttachfile(attachFileList, si.getStaffId());
		return si;
	}

	public void resignatStaff(StaffInfo staff) {
		this.getStaffFileDao().updateWorkStatus(staff);
	}

	@Override
	public List<StaffInfo> getStaffFileByStaffName(String name) {
		return getStaffFileDao().getStaffFileByStaffName(name);
	}

	@Override
	public int getStaffFileCount(StaffInfo staff, String entryDateFrom,String entryDateTo) {
		return getStaffFileDao().getStaffFileCount(staff,entryDateFrom,entryDateTo);
	}

	@Override
	public StaffInfo getStaffFileByUserId(String id) {
		return getStaffFileDao().getStaffInfoByUserId(id);
	}

	@Override
	public void auditStaff(StaffInfo staff) {
		getStaffFileDao().updateAuditStatus(staff.getStaffId());
	}

}
